unit udmMain;

interface

uses
  SysUtils, Classes,
  DBClient,
  uDIOCPConnection, uDIOCPQueryExecuter, uDIOCPApplyExecuter;

type
  TdmMain = class(TDataModule)
    procedure DataModuleCreate(Sender: TObject);
  private
    FApplyExecuter: TDIOCPApplyExecuter;
    FIOCPConnection: TDIOCPConnection;
    FQueryExecuter: TDIOCPQueryExecuter;

  public
    procedure reloadConfig;

    destructor Destroy; override;

    property ApplyExecuter: TDIOCPApplyExecuter read FApplyExecuter;

    property IOCPConnection: TDIOCPConnection read FIOCPConnection;

    property QueryExecuter: TDIOCPQueryExecuter read FQueryExecuter;





  end;

var
  dmMain: TdmMain;

implementation

uses
  IniFiles;

{$R *.dfm}

procedure TdmMain.DataModuleCreate(Sender: TObject);
begin
  FIOCPConnection := TDIOCPConnection.Create;
  FQueryExecuter := TDIOCPQueryExecuter.Create();
  FQueryExecuter.setConnection(FIOCPConnection);
  FApplyExecuter := TDIOCPApplyExecuter.Create();
  FApplyExecuter.setConnection(FIOCPConnection);
  reloadConfig;
end;

destructor TdmMain.Destroy;
begin
  FQueryExecuter.Free;
  FApplyExecuter.Free;
  FIOCPConnection.Free;
  inherited Destroy;
end;

procedure TdmMain.reloadConfig;
var
  lvINI:TIniFile;
begin
  lvINI := TIniFile.Create(ExtractFilePath(ParamStr(0)) + 'config\app.ini.config');
  try
    FIOCPConnection.close;
    FIOCPConnection.Host := lvINI.ReadString('server', 'host', '');
    FIOCPConnection.Port := lvINI.ReadInteger('server', 'port', 0);
  finally
    lvINI.Free;
  end;

end;

end.
